import color from "../../kernel/tools/color";
import { ctx } from "../inter";
/**
 * 记录请求
 */
const requestRecord = (ctx:ctx)=>{
    let time:any = global.time();
    return ()=>{
        !time && (time=global.time())
        let sj = ((global.time()-time)/1000).toFixed(3);
        let str = global.date('Y-d-m H:i:s ')+ctx.res.statusCode+" "+sj+"ms"+" "+ctx.req.method+" "+ctx.req.url;
        switch (ctx.res.statusCode){
          case 203:
          case 200:{
            console.log(color("绿色",str));
            break;
          }
          case 404:{
            console.log(color("红色",str));
            break;
          }
          case 500:{
            console.log(color("黄色",str));
            break;
          }
          default :{
            console.log(color("绿色",str));
            break;
          }
        }
        console.log();
      }
}

if(module) module.exports = requestRecord;
export default requestRecord;